import getPageJson from '../libs/getPageJson.js';
export default {
	methods: {
		initTabTitle(tabTitle) {
			tabTitle.activeIndex = tabTitle.style.activeIndex || 0;
			tabTitle.common.links.forEach(()=>{
				tabTitle.pages.push(null)
			})
			this.getTabTitleData(tabTitle)
		},
		getTabTitleData(tabTitle){
			var item = tabTitle.common.links[tabTitle.activeIndex];
			if (!item.pageId) {
				return;
			}
			if(tabTitle.pages[tabTitle.activeIndex]){
				return
			}
			tabTitle.pages.forEach(page=>{
				if(page){
					page.active = false
				}
			})
			getPageJson(item.pageId, '2', true).then(page => {
				page.active = true
				tabTitle.pages.splice(tabTitle.activeIndex, 1, page);
				uni.$emit('tabTitle-' + this.pageConfig.cid, page);
			})
		},
		tabTitleChange(index, tabTitle) {
			tabTitle.activeIndex = index;
			if(tabTitle.pages[index]){
				tabTitle.pages[index].active = true
				uni.$emit('tab-list-gap-'+tabTitle.pages[index].cid)
			}else{
				this.getTabTitleData(tabTitle)
			}
		}
	}
}
